package com.zhn.usermanager.controller;

import com.zhn.usermanager.util.GetAndPost;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/weather")
public class WeatherController {
    @GetMapping("/select")
    public Map<String, Object> select(@RequestParam(required = false, defaultValue = "成都")String cityName) {
        String url = "http://apis.juhe.cn/simpleWeather/query?city=%E6%88%90%E9%83%BD&key=8c1fe704069e1332a4ff00895a04eaa5";
        String s = GetAndPost.requestGet(url);
        JSONObject jsonObject = new JSONObject(s);
        jsonObject.put("code", 0);
        jsonObject.put("count", 1);
        jsonObject.put("msg", "成功");
        return jsonObject.toMap();

//        String city = jsonObject.getString("city");
//        JSONArray jsonArray = new JSONArray();
//        JSONArray jsonArray1 = jsonArray.put(city);
//        jsonObject.put("code", 0);
//        jsonObject= jsonObject.put("city", city);
//        return jsonObject;

    }
}
